package com.stox.ui.swing.util;

import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public class ImageIconLoader {

	private static final int iconWidth = 20;
	private static final int iconHeight = 20;
	
	private static String getPath(String name){
		return System.getProperty("path.image")+File.separator+name;
	}
	
	public static ImageIcon loadImageIcon(String name){
		ImageIcon icon = null;
		try {
			icon = new ImageIcon((ImageIO.read(new File(getPath(name)))
					.getScaledInstance(iconWidth,iconHeight, Image.SCALE_SMOOTH)));
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return icon;
	}
	
	public static ImageIcon loadImageIcon(String name,int width,int  height){
		ImageIcon icon = null;
		try {
			icon = new ImageIcon(
					(ImageIO.read(new File(getPath(name)))
					.getScaledInstance(width,height, Image.SCALE_SMOOTH)));
		} catch (IOException e) {
			e.printStackTrace();
		}
		return icon;
	}
	
	public static Image loadImage(String name){
		try {
				return ImageIO.read(new File(getPath(name)));
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
}
